﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Read.Api.Application.Command.FamingWay;

namespace Traceability_Management.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FamingAllController : ControllerBase
    {
        IMediator mediator;

        public FamingAllController(IMediator mediator)
        {
            this.mediator = mediator;
        }

   
        /// <summary>
        /// 中介者模式
        /// </summary>
        /// <param name="Farmings"></param>
        /// <returns></returns>
        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="Farmings"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<ApiResult<int>> AddFaming(Farmings Farmings)
        {
            try
            {
                AddFamingWayCommand AddFamingWayCommand = new AddFamingWayCommand() 
                {
                    Farmings = Farmings
                };
                return await mediator.Send(AddFamingWayCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<Farmings>> FirstFarming([FromQuery] FirstFarmingWayCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpPost]
        public async Task<ApiResult<int>> UpdateFaming(Farmings Farmings)
        {
            try
            {
                 UpdateFamingWayCommand UpdateFamingWayCommand = new UpdateFamingWayCommand()
                {
                    Farmings = Farmings
                };
                return await mediator.Send(UpdateFamingWayCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<int>> CheckFarming([FromQuery] CheckFarmingImagesCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<int>> CheckCompany([FromQuery] CheckCompanyImagesCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
